package com.google.gwt.maps.v3.client.streetview;

import java.util.ArrayList;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.maps.v3.client.base.HasLatLng;
import com.google.gwt.maps.v3.client.base.LatLng;
import com.google.gwt.maps.v3.client.streetview.impl.StreetViewPanoramaImpl;
import com.google.gwt.user.client.Element;

public class StreetViewPanorama implements HasStreetViewPanorama {

  private JavaScriptObject jso;
  
  public static final StreetViewPanoramaImpl impl = StreetViewPanoramaImpl.impl;
  
  public StreetViewPanorama(JavaScriptObject jso) {
    this.jso = jso;
  }
  
  public StreetViewPanorama(Element container) {
    this(impl.construct(container));
  }
  
  public StreetViewPanorama(Element container, HasStreetViewPanoramaOptions opts) {
    this(impl.construct(container, opts.getJso()));
  }
  
  @Override
  public ArrayList<HasStreetViewLink> getLinks() {
    final ArrayList<HasStreetViewLink> links = new ArrayList<HasStreetViewLink>();
    final JsArray<JavaScriptObject> linksJso = impl.getLinks(jso);
    if (linksJso != null) {
      for (int i = 0; i < linksJso.length(); ++i) {
        final JavaScriptObject linkJso = linksJso.get(i);
        final HasStreetViewLink link = new StreetViewLink(linkJso);
        links.add(link);
      }
    }
    return links;
  }

  @Override
  public String getPano() {
    return impl.getPano(jso);
  }

  @Override
  public HasLatLng getPosition() {
    return new LatLng(impl.getPosition(jso));
  }

  @Override
  public HasStreetViewPov getPov() {
    return new StreetViewPov(impl.getPov(jso));
  }

  @Override
  public boolean getVisible() {
    return impl.getVisible(jso);
  }

  @Override
  public void setPano(String pano) {
    impl.setPano(jso, pano);
  }

  @Override
  public void setPosition(HasLatLng position) {
    impl.setPosition(jso, position.getJso());
  }

  @Override
  public void setPov(HasStreetViewPov pov) {
    impl.setPov(jso, pov.getJso());
  }

  @Override
  public void setVisible(boolean visible) {
    impl.setVisible(jso, visible);
  }

  @Override
  public JavaScriptObject getJso() {
    return jso;
  }  
}
